(define-module (submit)
  #:use-module (decode)
  #:export (
            submit-response
            ))


(define (submit-response bv)
  ;;'((h1 "Thank you for submitting your request!  We will reach out to you soon!"))
  ;;(decode bv)
  ;;(verify-request)
  ;;(chdir "/var/www/html/myift.com/public_html/responses/")
  (let ([filename (let loop ([n 1])
                    (define temp-filename
                      (string-append "responses/submit" (number->string n) ".txt"))
                    ;; (display (string-append  "loop " (number->string n) "\n"))
                    ;; (display temp-filename)
                    ;; (display "\n")
                    (if (access? temp-filename F_OK)
                        (loop (+ n 1))
                        temp-filename))])
    ;; (display "after loop file name is: ")
    ;; (display filename)
    ;; (display "\n")
    (with-output-to-file (string-append filename)
      (lambda ()
        (let loop ([alist (decode bv)])
          (if (null? alist)
              '()
              (begin
                (display " \n")
                (display (car alist))
                (display "\n")
                ;;'(car alist (loop (cdr alist)))
                (loop (cdr alist)))))
        ))
    `((div (@ (class "container"))
           (div (@ (class "row"))
                (div (@ (class "col-sm-12")))
                (h1 "We have received your inquiry!")
                (h2 "We will reach out to your shortly!")
                (p "Thank you!")
                (p ,filename)))))

  ;;(define (email-response))
  )
